package com.iakuil.poc.web;

import org.springframework.security.oauth2.provider.token.ConsumerTokenServices;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

import java.security.Principal;

@RestController
public class OAuthController {

    private final ConsumerTokenServices consumerTokenServices;

    public OAuthController(ConsumerTokenServices consumerTokenServices) {
        this.consumerTokenServices = consumerTokenServices;
    }

    /**
     * 获取受权用户信息
     */
    @GetMapping("/user")
    public Principal user(Principal user) {
        return user;
    }

    /**
     * 注销登录
     */
    @PostMapping(value = "/logout")
    public void revokeToken(String accessToken) {
        consumerTokenServices.revokeToken(accessToken);
    }
}